package cn.hua.trip.base.domain;

import cn.hua.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

/**
 * 攻略文章
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class StrategyDetail extends BaseDomain{
    public static final int STATE_NOMAL = 1; //草稿
    public static final int STATE_RELEASE = 2; //发布状态

    private String title; //标题

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date createTime;  //创建时间

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date releaseTime;  //发布时间

    private Integer sequence; //序号

    private StrategyCatalog catalog; //攻略分类

    private String coverUrl; //封面

    private Integer state =STATE_NOMAL; //状态

    //关联内容
    private StrategyContent strategyContent;



    public String getJsonString(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",getId());
        map.put("title",title);
        map.put("sequence",sequence);
        map.put("coverUrl",coverUrl);
        map.put("state",state);
        if (catalog!=null){
            map.put("catalogId",catalog.getId());
        }
        return JSONUtil.toJSONString(map);
    }

    public String getStateDisplay(){
        if (state==null) {
            return "";
        }
        return  state ==STATE_NOMAL?"待发布":"发布";
    }
}